Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.DC

Public Class ClearFieldsController
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)

    End Sub

    Private Sub ClearFieldsController_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        'Makes the ClearFields Action enabled if the current Detail View's ViewEditMode property
        ' is set to ViewEditMode.Edit
        'ClearFieldsAction.Enabled.SetItemValue("EditMode", (CType(View, DetailView)).ViewEditMode = ViewEditMode.Edit)
        'AddHandler (CType(View, DetailView)).ViewEditModeChanged, AddressOf ClearFieldsController_ViewEditModeChanged
    End Sub

    'Manages the ClearFields Action enabled state
    Private Sub ClearFieldsController_ViewEditModeChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
        ClearFieldsAction.Enabled.SetItemValue("EditMode", _
            (CType(View, DetailView)).ViewEditMode = ViewEditMode.Edit)
    End Sub



    Private Sub ClearFieldsAction_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles ClearFieldsAction.Execute

        For Each item As PropertyEditor In (CType(View, DetailView)).GetItems(Of PropertyEditor)()
            If (item.AllowEdit) Then
                Try
                    item.PropertyValue = Nothing
                Catch e1 As IntermediateMemberIsNullException
                    item.Refresh()
                End Try
            End If
        Next item

    End Sub

End Class
